<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <link href="../../css/admin/style.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.8.3.min.js" type="text/javascript"></script >
    <script>
        $(function (){
            $.get("../../login/getUserList",function (res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else {
                    var str="";
                    for (let i = 0; i < res.data.length; i++) {
                        var imgsrc =  "http://127.0.0.1:8080/userImg/"+res.data[i].account+"/"+res.data[i].heading;
                        str += "<tr align='center'>";
                        str+="<td>"+(i+1)+"</td>";
                        str+="<td>"+res.data[i].account+"</td>";
                        str+="<td>"+res.data[i].nickname+"</td>";
                        str+="<td>"+res.data[i].sex+"</td>";
                        str+="<td>"+res.data[i].mailbox+"</td>";
                        str+="<td>"+res.data[i].phone+"</td>";
                        str+="<td>"+res.data[i].address+"</td>";
                        str+="<td><img src='"+imgsrc+"' width='30' height='30'/></td>";
                        str+="<td>"+ (new Date(res.data[i].opertime).toLocaleString())+"</td>";
                        if (res.data[i].accstate==0){
                            str+="<td>"+"正常"+"</td>";
                            str+="<td><a href='javaScript:void(0)' onclick='toupdate("+res.data[i].id+",1"+")' class='tablelink'>封号</a></td> "
                        }else {
                            str+="<td>"+"封号"+"</td>";
                            str+="<td><a href='javaScript:void(0)' onclick='toupdate("+res.data[i].id+",0"+")' class='tablelink'>解封</a></td> "
                        }
                        str+="</tr>";
                    }
                    $("#tableId").append(str);
                }
            },"json")
        })
        function toupdate(id,accstate) {
            if(confirm("您确定要修改用户账号状态吗?")) {
                $.get("../../login/updateaccstate",{id:id,accstate:accstate}, function (res) {
                    if (res.code == 202) {
                        window.parent.location.replace("../login.html");
                    } else if (res.code == 500) {
                        alert(res.msg);
                    } else {
                        alert(res.msg);
                        location.reload();
                    }
                })
            }
        }
    </script>
</head>
<body>
<div class="rightinfo">

    <!--数据列表 -->
    <table class="tablelist" id="tableId">
        <tr>
            <th >ID</th>
            <th >账号</th>
            <th >昵称</th>
            <th >性别</th>
            <th >邮箱</th>
            <th >手机</th>
            <th >地址</th>
            <th >头像</th>
            <th >注册时间</th>
            <th >账号状态</th>
            <th>操作</th>
        </tr>

    </table>
</div>
</body>
</html>